﻿using System;
using System.Windows.Forms;
using Mbs.Collections;
using Mbs.Modularity.AddIns;
using NUnit.Framework;

namespace Mbs.Test.ElementBuilder
{
    [TestFixture]
    public class AddInItemTest:TestBase
    {
        [Test]
        public void BuildTest()
        {
            //    <Item  Id="MainMenu"
            //    Label="主菜单"
            //    Type="MenuStrip"
            //    IsLeaf="false"/>
            //<Item  Id="ToolBar"
            //    Label="ToolBar"
            //    Type="ToolStrip"
            //    IsLeaf="false"/>
            var attrs = new PropertySet(StringComparer.InvariantCultureIgnoreCase);
            attrs.Set("Id", "MainMenu");
            attrs.Set("Type", "MenuStrip");
            attrs.Set("IsLeaf", "false");


            var addinItem = new AddInItem("Test AddIn", null, attrs);

            var mainMenu = addinItem.Build(null) as MenuStrip;
            Assert.IsNotNull(mainMenu);

            var mainMenu2 = ServiceLocator.Current.Get<MenuStrip>(addinItem.Path);
            Assert.AreSame(mainMenu, mainMenu2);

            Assert.IsTrue(string.Equals("Test AddIn", addinItem.AddInName));
            Assert.IsTrue(string.Equals("MainMenu", addinItem.Id));
            Assert.IsTrue(string.Equals("MainMenu", addinItem.Path));
            Assert.IsTrue(string.Equals("MenuStrip", addinItem.Type, StringComparison.InvariantCultureIgnoreCase));


            attrs.Set("Id", "ToolBar");
            attrs.Set("Type", "ToolStrip");
            attrs.Set("IsLeaf", "false");
            addinItem = new AddInItem("Test AddIn", null, attrs);

            var toolStrip = addinItem.Build(null) as ToolStrip;
            Assert.IsNotNull(toolStrip);
        }
    }
}
